package com.zuul.fallback;

import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;

/**
 * service-provider服务熔断
 * 
 * @author zincredible
 * @date 2019-07-12 14:46:90
 *
 */
@Component
public class ConsumerServiceFallback implements FallbackProvider {

	@Override
	public String getRoute() {
		// api服务id，如果需要所有调用都支持回退，则return "*"或return null
		return "service-provider";
	}

	/**
	 * 如果请求用户服务失败，返回对应信息给消费者客户端
	 */
	@Override
	public ClientHttpResponse fallbackResponse(String route, Throwable cause) {

		return new CommonClientHttpResponse(getRoute());
	}

}
